import numpy as np
import pandas as pd
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
from email.header import Header
from io import open
'''
1.压缩 -> 发送
2. 日志
'''
sender = '15732893386@163.com'
# sender_pswd = 'wanghaobin@123'
sender_pswd = 'MLCDYIOYHFEOQJFC'
receivers = ['940914943@qq.com','1834788208@qq.com']
subject = 'obj' #  zhuti
attachment = ['C:\\Users\\g\\Desktop\\code.txt'] # 附件
# attachment = [] # wu fu jian
mail_body = '''
     test。
'''

mail_object = MIMEMultipart()
mail_object['From'] = sender
mail_object['To'] = ';'.join(receivers)
mail_object['Subject'] = Header(subject, 'utf-8')
mail_object.attach(MIMEText(mail_body, 'html', 'utf-8')) # 邮件正文
for j in attachment:
    print(open(j, mode='r', encoding='utf-8').read())
    file = MIMEText(open(file=j, mode='r', encoding='utf-8').read())
    file['Content-Type'] = 'application/octet-stream'
    file['Content-Disposition'] = 'attachment; filename="%s"'%j
    mail_object.attach(file)

try:
    smtp_obj = smtplib.SMTP('smtp.163.com') # 139 SMTP
    smtp_obj.set_debuglevel(0)
    smtp_obj.login(sender, sender_pswd)
    smtp_obj.sendmail(sender, receivers, mail_object.as_string())
    smtp_obj.quit()
except Exception as e:
    print(e)